
def calc_h_out(h_in, padding, kernel, stride):
    h_out = (h_in + 2 * padding[0] - 1 * (kernel[0] - 1) - 1) / stride[0] + 1
    return h_out

def calc_padding(h_in, h_out, kernel, stride):
    # h_out = (h_in + 2 * padding[0] - 1 * (kernel[0] - 1) - 1) / stride[0] + 1
    # h_out - 1 = (h_in + 2 * padding[0] - 1 * (kernel[0] - 1) - 1) / stride[0]
    # (h_out - 1) * stride[0] = h_in + 2 * padding[0] - 1 * (kernel[0] - 1) - 1
    padding = ((h_out - 1) * stride[0] - h_in + 1 + 1 * (kernel[0] - 1))/2
    return padding

if __name__ == "__main__":
    padding = (0, 0)
    kernel = (2, 2)
    stride = (1, 1)
    print(type(stride))
    h_in = 10
    # h_out = 224
    # h_out = calc_h_out(h_in, padding, kernel, stride)
    # print(h_out)
    h_out = 10
    pad = calc_padding(h_in, h_out, kernel, stride)
    print(pad)
